package com.lovesher.payment.web;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.druid.support.json.JSONUtils;

/**
 * 自动生成mapper文件
 * 
 * @author tupengxiong
 *
 */
public class MybatisMapperCreator {

	/**
	 ********************************** 使用前必读*******************
	 ** 
	 ** 使用前请将moduleName更改为自己模块的名称即可（一般情况下与数据库名一致），其他无须改动。
	 ** 
	 *********************************************************** 
	 ************************** 存在的问题**************** Service 里面import 有多余的 Dscm 文件没有生成 多bean
	 * 生成的时候配置文件是不追加而是覆盖
	 */

	private final String type_char = "char";

	private final String type_date = "date";

	private final String type_timestamp = "timestamp";

	private final String type_int = "int";

	private final String type_bigint = "bigint";

	private final String type_text = "text";

	private final String type_bit = "bit";

	private final String type_double = "double";

	private final String type_float = "float";

	private final String type_decimal = "decimal";

	private final String type_blob = "blob";

	// private final String moduleName = "resposity"; //
	// 对应模块名称（根据自己模块做相应调整!!!务必修改^_^）

	private final String BASE_PATH = "E:\\work\\git-repo\\gitee\\payment";

	private final String BEAN_PATH = BASE_PATH
			+ "/payment-common/src/main/java/com/lovesher/payment/common/resposity/bean";

	private final String MAPPER_PATH = BASE_PATH
			+ "/payment-service/src/main/java/com/lovesher/payment/service/resposity/mapper";

	private final String XML_PATH = BASE_PATH + "/payment-web/src/main/resources/ibatis";

	private final String mapper_define_xml_path = BASE_PATH + "/payment-web/src/main/resources/";

	private final String DAO_PATH = BASE_PATH
			+ "/payment-service/src/main/java/com/lovesher/payment/service/resposity/dao";

	private final String SERVICE_PATH = BASE_PATH + "/payment-common/src/main/java/com/lovesher/payment/common/service";

	private final String SERVICE_IMPL_PATH = BASE_PATH
			+ "/payment-service/src/main/java/com/lovesher/payment/service/service/impl";

	private final String DAO_IMPL_PATH = BASE_PATH
			+ "/payment-service/src/main/java/com/lovesher/payment/service/resposity/dao/impl";

	private final String BEAN_PACKAGE = "com.lovesher.payment.common.resposity.bean";

	private final String MAPPER_PACKAGE = "com.lovesher.payment.service.resposity.mapper";

	private final String DAO_PACKAGE = "com.lovesher.payment.service.resposity.dao";

	private final String BASE_DAO_PACKAGE = "com.lovesher.payment.service.resposity.base.DaoBase";

	private final String DAO_IMPL_PACKAGE = "com.lovesher.payment.service.resposity.dao.impl";

	private final String BASE_SERVICE_PACKAGE = "com.lovesher.payment.common.service.BaseService";

	private final String SERVICE_PACKAGE = "com.lovesher.payment.common.service";

	private final String SERVICE_IMPL_PACKAGE = "com.lovesher.payment.service.service.impl";

	private final String driverName = "com.mysql.jdbc.Driver";

	private final String user = "root";

	private final String password = "root";

	private final String url = "jdbc:mysql://127.0.0.1:3306/dc_payment?characterEncoding=utf8";

	private String tableName = null;

	private String beanName = null;

	private String mapperName = null;

	private String _mapperName = null;

	private String daoName = null;

	private String daoImplName = null;

	private String serviceName = null;

	private String serviceImplName = null;

	private Connection conn = null;

	private String[] excuteTables = new String[] { "dw_search_pay_res_task" };

	private void init() throws ClassNotFoundException, SQLException {
		Class.forName(driverName);
		conn = DriverManager.getConnection(url, user, password);
	}

	/**
	 * 获取所有的表
	 * 
	 * @return
	 * @throws SQLException
	 */
	private List<String> getTables() throws SQLException {
		List<String> tables = new ArrayList<String>();
		PreparedStatement pstate = conn.prepareStatement("show tables");
		ResultSet results = pstate.executeQuery();
		while (results.next()) {
			String tableName = results.getString(1);
			tables.add(tableName);
			/*for (String tempTable : excuteTables) {
				if (tempTable.equals(tableName)) {
					tables.add(tableName);
					break;
				}
			}*/
		}
		System.out.println(JSONUtils.toJSONString(tables));
		return tables;
	}

	private void processTable(String table) {
		StringBuffer sb = new StringBuffer(table.length());
		String tableNew = table.toLowerCase();
		String[] tables = tableNew.split("_");
		String temp = null;
		for (int i = 1; i < tables.length; i++) {
			temp = tables[i].trim();
			sb.append(temp.substring(0, 1).toUpperCase()).append(temp.substring(1));
		}
		beanName = sb.toString();
		mapperName = beanName + "Mapper";
		_mapperName = shotFirst(mapperName);
		daoName = beanName + "Dao";
		daoImplName = beanName + "DaoImpl";
		serviceName = beanName + "Service";
		serviceImplName = serviceName + "Impl";
	}

	/**
	 * 首字母转小写
	 * 
	 * @return
	 */
	private String shotFirst(String str) {
		char[] chars = new char[1];
		chars[0] = str.charAt(0);
		String temp = new String(chars);
		if (chars[0] >= 'A' && chars[0] <= 'Z') {
			str = str.replaceFirst(temp, temp.toLowerCase());
		}
		return str;
	}

	private String processType(String type) {
		if (type.indexOf(type_char) > -1) {
			return "java.lang.String";
		} else if (type.indexOf(type_bigint) > -1) {
			return "java.lang.Long";
		} else if (type.indexOf(type_int) > -1) {
			return "java.lang.Integer";
		} else if (type.indexOf(type_date) > -1) {
			return "java.util.Date";
		} else if (type.indexOf(type_text) > -1) {
			return "java.lang.String";
		} else if (type.indexOf(type_timestamp) > -1) {
			return "java.util.Date";
		} else if (type.indexOf(type_bit) > -1) {
			return "java.lang.Boolean";
		} else if (type.indexOf(type_decimal) > -1) {
			return "java.math.BigDecimal";
		} else if (type.indexOf(type_blob) > -1) {
			return "byte[]";
		} else if (type.indexOf(type_double) > -1) {
			return "java.lang.Double";
		} else if (type.indexOf(type_float) > -1) {
			return "java.lang.Float";
		}

		return null;
	}

	private String processField(String field) {
		StringBuffer sb = new StringBuffer(field.length());
		String[] fields = field.split("_");
		String temp = null;
		sb.append(fields[0]);
		for (int i = 1; i < fields.length; i++) {
			temp = fields[i].trim();
			sb.append(temp.substring(0, 1).toUpperCase()).append(temp.substring(1));
		}
		return sb.toString();
	}

	/**
	 * 将实体类名首字母改为小写
	 * 
	 * @param beanName
	 * @return
	 */
	@SuppressWarnings("unused")
	private String processResultMapId(String beanName) {
		return beanName.substring(0, 1).toLowerCase() + beanName.substring(1);
	}

	/**
	 * 构建类上面的注释
	 * 
	 * @param bw
	 * @param text
	 * @return
	 * @throws IOException
	 */
	private BufferedWriter buildClassComment(BufferedWriter bw, String text) throws IOException {
		bw.newLine();
		bw.newLine();
		bw.write("/**");
		bw.newLine();
		bw.write(" * ");
		bw.newLine();
		bw.write(" * " + text);
		bw.newLine();
		bw.write(" * ");
		bw.newLine();
		bw.write(" **/");
		return bw;
	}

	/**
	 * 生成实体类
	 * 
	 * @param columns
	 * @param types
	 * @param comments
	 * @throws IOException
	 */
	private void buildEntityBean(List<String> columns, List<String> types, List<String> comments, String tableComment)
			throws IOException {
		File folder = new File(BEAN_PATH);
		if (!folder.exists()) {
			folder.mkdir();
		}
		File beanFile = new File(BEAN_PATH, beanName + ".java");
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(beanFile)));
		bw.write("package " + BEAN_PACKAGE + ";");
		bw.newLine();
		bw.write("import java.io.Serializable;");
		bw.newLine();
		bw = buildClassComment(bw, tableComment);
		bw.newLine();
		bw.write("@SuppressWarnings(\"serial\")");
		bw.newLine();
		bw.write("public class " + beanName + " implements Serializable {");
		bw.newLine();
		bw.newLine();
		int size = columns.size();
		for (int i = 0; i < size; i++) {
			bw.write("\t/**" + comments.get(i) + "**/");
			bw.newLine();
			bw.write("\tprivate " + processType(types.get(i)) + " " + processField(columns.get(i)) + ";");
			bw.newLine();
			bw.newLine();
		}
		bw.newLine();
		String tempField = null;
		String _tempField = null;
		String tempType = null;
		for (int i = 0; i < size; i++) {
			tempType = processType(types.get(i));
			_tempField = processField(columns.get(i));
			tempField = _tempField.substring(0, 1).toUpperCase() + _tempField.substring(1);
			bw.newLine();
			bw.write("\t/** 设置" + comments.get(i) + " **/");
			bw.newLine();
			bw.write("\tpublic void set" + tempField + "(" + tempType + " " + _tempField + "){");
			bw.newLine();
			bw.write("\t\tthis." + _tempField + " = " + _tempField + ";");
			bw.newLine();
			bw.write("\t}");
			bw.newLine();
			bw.newLine();
			bw.write("\t/** 获取" + comments.get(i) + " **/");
			bw.newLine();
			bw.write("\tpublic " + tempType + " get" + tempField + "(){");
			bw.newLine();
			bw.write("\t\treturn this." + _tempField + ";");
			bw.newLine();
			bw.write("\t}");
			bw.newLine();
		}
		bw.newLine();
		bw.write("}");
		bw.newLine();
		bw.flush();
		bw.close();
	}

	/**
	 * 构建DAO文件
	 * 
	 * @throws IOException
	 */
	private void buildDao() throws IOException {
		File folder = new File(DAO_PATH);
		if (!folder.exists()) {
			folder.mkdirs();
		}

		File daoFile = new File(DAO_PATH, daoName + ".java");
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(daoFile), "utf-8"));
		bw.write("package " + DAO_PACKAGE + ";");
		bw.newLine();
		bw.write("import " + BEAN_PACKAGE + "." + beanName + ";");
		bw.newLine();
		bw.write("import " + BASE_DAO_PACKAGE + ";");
		bw = buildClassComment(bw, daoName);
		bw.newLine();
		bw.write("public interface " + daoName + " extends DaoBase<" + beanName + ">{");
		bw.newLine();
		bw.newLine();
		bw.write("}");
		bw.flush();
		bw.close();
	}

	/**
	 * 构建DAOImpl文件
	 * 
	 * @throws IOException
	 */
	private void buildDaoImpl() throws IOException {
		File folder = new File(DAO_IMPL_PATH);
		if (!folder.exists()) {
			folder.mkdirs();
		}
		File daoFile = new File(DAO_IMPL_PATH, daoImplName + ".java");
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(daoFile), "utf-8"));
		bw.write("package " + DAO_IMPL_PACKAGE + ";");
		bw.newLine();
		bw.newLine();
		bw.write("import " + BEAN_PACKAGE + "." + beanName + ";");
		bw.newLine();
		bw.write("import " + MAPPER_PACKAGE + "." + mapperName + ";");
		bw.newLine();
		bw.write("import com.lovesher.payment.service.resposity.base.DaoDefault;");
		bw.newLine();
		bw.write("import " + DAO_PACKAGE + "." + daoName + ";");
		bw.newLine();
		bw.write("import javax.annotation.Resource;");
		bw.newLine();
		bw.write("import org.springframework.stereotype.Service;");
		bw.newLine();
		bw = buildClassComment(bw, daoImplName);
		bw.newLine();
		bw.write("@Service(\"" + this.shotFirst(daoName) + "\")");
		bw.newLine();
		bw.write("public class " + daoImplName + " extends DaoDefault<" + beanName + ", " + mapperName + "> implements "
				+ daoName + "{");
		bw.newLine();
		bw.newLine();
		bw.write("\t@Resource");
		bw.newLine();
		bw.write("\tprivate " + mapperName + " " + _mapperName + ";");
		bw.newLine();
		bw.newLine();
		bw.write("\t@Override");
		bw.newLine();
		bw.write("\tpublic " + mapperName + " getMapper() {");
		bw.newLine();
		bw.write("\t\treturn " + this.shotFirst(mapperName) + ";");
		bw.newLine();
		bw.write("\t}");
		bw.newLine();
		bw.newLine();
		bw.write("}");
		bw.flush();
		bw.close();
	}

	/**
	 * 构建Service文件
	 * 
	 * @throws IOException
	 */
	private void buildService() throws IOException {
		File folder = new File(SERVICE_PATH);
		if (!folder.exists()) {
			folder.mkdirs();
		}

		File serviceFile = new File(SERVICE_PATH, serviceName + ".java");
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
		bw.write("package " + SERVICE_PACKAGE + ";");
		bw.newLine();
		bw.newLine();
		bw.write("import " + BASE_SERVICE_PACKAGE + ";");
		bw.newLine();
		bw.write("import " + BEAN_PACKAGE + "." + beanName + ";");
		bw.newLine();
		bw = buildClassComment(bw, serviceName);
		bw.newLine();
		bw.newLine();
		bw.write("public interface " + serviceName + " extends BaseService<" + beanName + ">{");
		bw.newLine();
		bw.write("}");
		bw.flush();
		bw.close();
	}

	/**
	 * 构建ServiceImpl文件
	 * 
	 * @throws IOException
	 */
	private void buildServiceImpl() throws IOException {
		File folder = new File(SERVICE_IMPL_PATH);
		if (!folder.exists()) {
			folder.mkdirs();
		}
		File daoFile = new File(SERVICE_IMPL_PATH, serviceImplName + ".java");
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(daoFile), "utf-8"));
		bw.write("package " + SERVICE_IMPL_PACKAGE + ";");
		bw.newLine();
		bw.newLine();
		bw.write("import " + BEAN_PACKAGE + "." + beanName + ";");
		bw.newLine();
		bw.write("import " + DAO_PACKAGE + "." + daoName + ";");
		bw.newLine();
		bw.write("import javax.annotation.Resource;");
		bw.newLine();
		bw.write("import org.springframework.stereotype.Service;");
		bw.newLine();
		bw.write("import " + SERVICE_PACKAGE + "." + serviceName + ";");
		bw.newLine();
		bw = buildClassComment(bw, serviceName);
		bw.newLine();
		bw.write("@Service(\"" + shotFirst(serviceName) + "\")");
		bw.newLine();
		bw.write("public class " + serviceImplName + " extends BaseServiceImpl<" + beanName + ", " + daoName
				+ "> implements " + serviceName + "{");
		bw.newLine();
		bw.newLine();
		bw.write("\t@Resource");
		bw.newLine();
		bw.write("\tprivate " + daoName + " " + this.shotFirst(daoName) + ";");
		bw.newLine();
		bw.newLine();
		bw.write("\t@Override");
		bw.newLine();
		bw.write("\tpublic " + daoName + " getDao() {");
		bw.newLine();
		bw.write("\t\treturn " + this.shotFirst(daoName) + ";");
		bw.newLine();
		bw.write("\t}");
		bw.newLine();
		bw.newLine();
		bw.write("}");
		bw.flush();
		bw.close();
	}

	/**
	 * 构建Mapper文件
	 * 
	 * @throws IOException
	 */
	private void buildMapper() throws IOException {
		File folder = new File(MAPPER_PATH);
		if (!folder.exists()) {
			folder.mkdirs();
		}

		File mapperFile = new File(MAPPER_PATH, mapperName + ".java");
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperFile), "utf-8"));
		bw.write("package " + MAPPER_PACKAGE + ";");
		bw.newLine();
		bw.newLine();
		bw.write("import " + BEAN_PACKAGE + "." + beanName + ";");
		bw.newLine();
		bw.write("import com.lovesher.payment.service.resposity.base.Mapper;");
		bw.newLine();
		bw = buildClassComment(bw, mapperName + "数据库操作接口类");
		bw.newLine();
		bw.write("public interface " + mapperName + " extends Mapper<" + beanName + ">{");
		bw.newLine();
		bw.write("}");
		bw.flush();
		bw.close();
	}

	/**
	 * 构建实体类映射XML文件
	 * 
	 * @param columns
	 * @param types
	 * @param comments
	 * @throws IOException
	 */
	private void buildMapperXml(List<String> columns, List<String> types, List<String> comments) throws IOException {
		File folder = new File(XML_PATH);
		if (!folder.exists()) {
			folder.mkdirs();
		}

		File mapperXmlFile = new File(XML_PATH, mapperName + ".xml");
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperXmlFile)));
		bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		bw.newLine();
		bw.write("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" ");
		bw.newLine();
		bw.write("    \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">");
		bw.newLine();
		bw.write("<mapper namespace=\"" + MAPPER_PACKAGE + "." + mapperName + "\">");
		bw.newLine();
		bw.newLine();

		buildSQL(bw, columns, types);

		bw.write("</mapper>");
		bw.flush();
		bw.close();
	}

	private void buildSQL(BufferedWriter bw, List<String> columns, List<String> types) throws IOException {
		int size = columns.size();
		String tempField = null;
		String _tempField = null;
		bw.write("\t<!-- 结果映射 resultMap-->");
		bw.newLine();
		bw.write("\t<resultMap id=\"BaseResultMap\" type=\"" + BEAN_PACKAGE + "." + beanName + "\">");
		for (int i = 0; i < size; i++) {
			_tempField = processField(columns.get(i));
			tempField = _tempField.substring(0, 1).toUpperCase() + _tempField.substring(1);
			bw.newLine();
			bw.write("\t\t <result column=\"" + columns.get(i) + "\" property=\"" + this.shotFirst(tempField) + "\"/>");
			if (i == size - 1) {
				bw.newLine();
				bw.write("\t</resultMap>");
			}
		}
		// 通用结果列
		bw.newLine();
		bw.newLine();
		bw.write("\t<!-- 通用查询结果列-->");
		bw.newLine();
		bw.write("\t<sql id=\"Base_Column_List\">");
		bw.newLine();

		bw.write("\t\t");
		for (int i = 0; i < size; i++) {
			bw.write("`");
			bw.write(columns.get(i));
			bw.write("`");
			if (i != size - 1) {
				bw.write(",");
			}
		}

		bw.newLine();
		bw.write("\t</sql>");
		bw.newLine();
		bw.newLine();

		// 查询（根据主键ID查询）
		bw.write("\t<!-- 查询（根据主键ID查询） -->");
		bw.newLine();
		bw.write("\t<select id=\"selectById\" resultMap=\"BaseResultMap\">");
		bw.newLine();
		bw.write("\t\t SELECT");
		bw.newLine();
		bw.write("\t\t <include refid=\"Base_Column_List\" />");
		bw.newLine();
		bw.write("\t\t FROM " + tableName);
		bw.newLine();
		bw.write("\t\t WHERE `" + columns.get(0) + "` = #{" + processField(columns.get(0)) + "}");
		bw.newLine();
		bw.write("\t</select>");
		bw.newLine();
		bw.newLine();
		// 查询完

		// 删除（根据主键ID删除）
		bw.write("\t<!--删除：根据主键ID删除-->");
		bw.newLine();
		bw.write("\t<delete id=\"deleteById\">");
		bw.newLine();
		bw.write("\t\t DELETE FROM " + tableName);
		bw.newLine();
		bw.write("\t\t WHERE `" + columns.get(0) + "` = #{" + processField(columns.get(0)) + "}");
		bw.newLine();
		bw.write("\t</delete>");
		bw.newLine();
		bw.newLine();
		// 删除完

		// 添加insert方法
		bw.write("\t<!-- 添加 -->");
		bw.newLine();
		bw.write("\t<insert id=\"insert\" parameterType=\"" + BEAN_PACKAGE + "." + beanName
				+ "\" useGeneratedKeys=\"true\" keyProperty=\"id\" >");
		bw.newLine();
		bw.write("\t<selectKey resultType=\"java.lang.Long\" order=\"AFTER\" keyProperty=\"id\"> ");
		bw.newLine();
		bw.write("\t\t SELECT last_insert_id() AS id ");
		bw.newLine();
		bw.write("\t\t </selectKey>");

		bw.newLine();
		bw.write("\t\t INSERT INTO " + tableName);
		bw.newLine();
		bw.write(" \t\t(");
		for (int i = 1; i < size; i++) {
			bw.write("`");
			bw.write(columns.get(i));
			bw.write("`");
			if (i != size - 1) {
				bw.write(",");
			}
		}
		bw.write(") ");
		bw.newLine();
		bw.write("\t\t VALUES ");
		bw.newLine();
		bw.write(" \t\t(");
		for (int i = 1; i < size; i++) {
			bw.write("#{" + processField(columns.get(i)) + "}");
			if (i != size - 1) {
				bw.write(",");
			}
		}
		bw.write(") ");
		bw.newLine();
		bw.write("\t</insert>");
		bw.newLine();
		bw.newLine();
		// 添加insert完

		// ----- 修改
		bw.write("\t<!-- 修 改-->");
		bw.newLine();
		bw.write("\t<update id=\"update\" parameterType=\"" + BEAN_PACKAGE + "." + beanName + "\">");
		bw.newLine();
		bw.write("\t\t UPDATE " + tableName);
		bw.newLine();
		bw.write("\t\t SET ");

		bw.newLine();
		tempField = null;
		for (int i = 1; i < size; i++) {
			if (columns.get(i) != "modify_time") {
				tempField = processField(columns.get(i));
				bw.write("\t\t\t <if test=\"" + tempField + " !=null\"> `" + columns.get(i) + "` = #{" + tempField
						+ "},</if>");
				bw.newLine();
			}
		}
		bw.write("\t\t modify_time = CURRENT_TIMESTAMP() ");
		bw.write("\t\t WHERE `" + columns.get(0) + "` = #{" + processField(columns.get(0)) + "}");
		bw.newLine();
		bw.write("\t</update>");
		bw.newLine();
		bw.newLine();
	}

	/**
	 * 获取所有的数据库表注释
	 * 
	 * @return
	 * @throws SQLException
	 */
	private Map<String, String> getTableComment() throws SQLException {
		Map<String, String> maps = new HashMap<String, String>();
		PreparedStatement pstate = conn.prepareStatement("show table status");
		ResultSet results = pstate.executeQuery();
		while (results.next()) {
			String tableName = results.getString("NAME");
			String comment = results.getString("COMMENT");
			maps.put(tableName, comment);
		}
		return maps;
	}

	public void generate() throws ClassNotFoundException, SQLException, IOException {
		init();
		String prefix = "show full fields from ";
		List<String> columns = null;
		List<String> types = null;
		List<String> comments = null;
		PreparedStatement pstate = null;
		List<String> tables = getTables();
		Map<String, String> tableComments = getTableComment();

		File folder = new File(mapper_define_xml_path);
		if (!folder.exists()) {
			folder.mkdirs();
		}
		for (String table : tables) {
			columns = new ArrayList<String>();
			types = new ArrayList<String>();
			comments = new ArrayList<String>();
			pstate = conn.prepareStatement(prefix + table);
			ResultSet results = pstate.executeQuery();
			while (results.next()) {
				columns.add(results.getString("FIELD"));
				types.add(results.getString("TYPE"));
				comments.add(results.getString("COMMENT"));
			}
			tableName = table;
			processTable(table);
			String tableComment = tableComments.get(tableName);
			buildEntityBean(columns, types, comments, tableComment);
			buildMapper();
			buildMapperXml(columns, types, comments);
			buildDao();
			buildDaoImpl();
			buildService();
			buildServiceImpl();
		}
		conn.close();
	}

	public static void main(String[] args) {
		try {
			new MybatisMapperCreator().generate();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}